import java.util.*;
import java.io.*;
public class Practice3 {
    /*
    链接https://www.nowcoder.com/questionTerminal/d1ac7f15d5dc40b39a7d6cb11a01407e
    手写快速读写模板, 我怕超时
    简单的模拟,重排偶数
     */
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static void main(String[] args) throws IOException{
        Scanner in = new Scanner(System.in);
        int q = in.nextInt();
        while(q-- > 0){
            //转成字符数组好用一点, 再转为int
            char[] ss = in.next().toCharArray();
            int n = Integer.parseInt(new String(ss));
            //先判断是不是偶数本身, 如果是直接输出
            if(n % 2 == 0){
                out.println(n);
                continue;
            }
            //判断是否存在偶数
            //存储个数
            int index = -1;
            for(int i = 0;i < ss.length;i++){
                if(ss[i] == '0' || ss[i] == '2' || ss[i] == '4' || ss[i] == '6' || ss[i] == '8'){
                    index = i;
                    break;
                }

            }
            //前导0的情况已经被我们排除了, 0不能出现在开始位置和最后一个位置
            //最后一个位置如果是0直接在上面就被干掉了, 第一个位置也不可能是0,所以不会出现前导零的情况
            if(index != -1){
                //有偶数直接交换, 没偶数直接输出-1
                char tmp = ss[index];
                ss[index] = ss[ss.length - 1];
                ss[ss.length - 1] = tmp;
                out.println(Integer.parseInt(new String(ss)));
            }else{
                out.println(-1);
            }

        }
        out.close();
    }
}
class Read{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }
    int nextInt()throws IOException{
        return Integer.parseInt(next());
    }
}